﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// ProjectEditForm.xaml 的交互逻辑
    /// </summary>
    public partial class ProjectEditForm : Window
    {
        public ProjectEditForm()
        {
            InitializeComponent();
        }

        CLoginUser userinfo = new CLoginUser();
        public ProjectEditForm(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;
            
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            CShopsProject model = new CShopsProject();

            model.projectid = Convert.ToInt32(this.lblId.Content);
            model.companyid = this.userinfo.CompanyId;
            model.projectname = this.txtProjectName.Text;
            model.developers = this.txtDevelopers.Text;
            model.address = this.txtAddress.Text;
            model.startdate = Convert.ToDateTime(this.dpStartDate.SelectedDate);
            model.enddate = Convert.ToDateTime(this.dpEndDate.SelectedDate);

            model.totalarea = Convert.ToDecimal(this.txtTotalarea.Text);
            model.buildarea = Convert.ToDecimal(this.txtBuildarea.Text);
            model.projectbuildarea = Convert.ToDecimal(this.txtProjectbuildarea.Text);

            ShopsProject bll = new ShopsProject();

            bll.Update(model);

            MessageBox.Show("保存成功！", "系统信息", MessageBoxButton.OK, MessageBoxImage.Information);

            this.Close();
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        public void ShowInfo(int Id)
        {
            ShopsProject bll = new ShopsProject();

            DataSet ds=bll.GetListByUpdate(Id.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                this.lblId.Content = Id.ToString();
                this.txtProjectName.Text = ds.Tables[0].Rows[0]["projectname"].ToString();
                this.txtDevelopers.Text = ds.Tables[0].Rows[0]["developers"].ToString();
                this.txtAddress.Text = ds.Tables[0].Rows[0]["address"].ToString();
                this.dpStartDate.SelectedDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["startdate"]);
                this.dpEndDate.SelectedDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["enddate"]);
                this.txtTotalarea.Text = ds.Tables[0].Rows[0]["totalarea"].ToString();
                this.txtBuildarea.Text = ds.Tables[0].Rows[0]["buildarea"].ToString();
                this.txtProjectbuildarea.Text = ds.Tables[0].Rows[0]["projectbuildarea"].ToString();
            }

        }
    }
}
